VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form frmAutoBackup 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Backup"
   ClientHeight    =   4050
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   7875
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   4050
   ScaleWidth      =   7875
   Begin VB.CheckBox chkEnabledBackup 
      Caption         =   "Enabled backup"
      Height          =   255
      Left            =   3600
      TabIndex        =   14
      Top             =   120
      Width           =   2535
   End
   Begin VB.CommandButton Command5 
      Caption         =   "Backup &Now"
      Height          =   375
      Left            =   1560
      TabIndex        =   12
      Top             =   3480
      Width           =   1335
   End
   Begin VB.CommandButton Command4 
      Caption         =   "&Close"
      Height          =   375
      Left            =   6360
      TabIndex        =   10
      Top             =   3480
      Width           =   1335
   End
   Begin VB.CommandButton Command3 
      Caption         =   "&OK"
      Height          =   375
      Left            =   4680
      TabIndex        =   9
      Top             =   3480
      Width           =   1215
   End
   Begin VB.CommandButton Command2 
      Caption         =   "&Apply"
      Height          =   375
      Left            =   3120
      TabIndex        =   8
      Top             =   3480
      Width           =   1455
   End
   Begin VB.OptionButton optManual 
      Caption         =   "Ask for backup"
      Height          =   375
      Left            =   3600
      TabIndex        =   7
      Top             =   2880
      Width           =   2175
   End
   Begin VB.OptionButton optAuto 
      Caption         =   "Auto backup"
      Height          =   375
      Left            =   3600
      TabIndex        =   6
      Top             =   2520
      Width           =   2055
   End
   Begin MSComCtl2.UpDown UpDown1 
      Height          =   375
      Left            =   4200
      TabIndex        =   5
      Top             =   2040
      Width           =   255
      _ExtentX        =   450
      _ExtentY        =   661
      _Version        =   393216
      Value           =   1
      Enabled         =   -1  'True
   End
   Begin VB.TextBox txtDay 
      Height          =   375
      Left            =   3600
      TabIndex        =   4
      Text            =   "1"
      Top             =   2040
      Width           =   615
   End
   Begin VB.CommandButton Command1 
      Caption         =   "..."
      Height          =   375
      Left            =   7200
      TabIndex        =   2
      Top             =   960
      Width           =   495
   End
   Begin VB.TextBox txtPath 
      Height          =   375
      Left            =   3600
      TabIndex        =   0
      Top             =   960
      Width           =   3495
   End
   Begin VB.Label Label4 
      Caption         =   "Notice: Path name does not allow to include space and special character  ~!`?@#$%^&*()<>,-+=."
      ForeColor       =   &H000000FF&
      Height          =   495
      Left            =   3600
      TabIndex        =   16
      Top             =   1440
      Width           =   3615
   End
   Begin VB.Image Image1 
      Height          =   1440
      Left            =   120
      Picture         =   "frmAutoBackup.frx":0000
      Top             =   120
      Width           =   1440
   End
   Begin VB.Label Label5 
      Caption         =   "days"
      Height          =   375
      Left            =   4560
      TabIndex        =   15
      Top             =   2040
      Width           =   1455
   End
   Begin VB.Label lblLastUpdate 
      Caption         =   "Last backup"
      Height          =   375
      Left            =   3600
      TabIndex        =   13
      Top             =   480
      Width           =   3015
   End
   Begin VB.Label Label3 
      Caption         =   "Last backup"
      Height          =   255
      Left            =   2520
      TabIndex        =   11
      Top             =   480
      Width           =   975
   End
   Begin VB.Label Label2 
      Caption         =   "Backup data every "
      Height          =   375
      Left            =   2160
      TabIndex        =   3
      Top             =   2040
      Width           =   1455
   End
   Begin VB.Label Label1 
      Caption         =   "Backup to"
      Height          =   375
      Left            =   2640
      TabIndex        =   1
      Top             =   960
      Width           =   855
   End
End
Attribute VB_Name = "frmAutoBackup"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Command1_Click() '.... select place to save
    txtPath.Text = BrowseForFolder(hwnd, "Please select a folder.")
    If Not CheckMSDOSFolderName(txtPath.Text) Then
       MsgBox "Notice: Path name does not allow to include space and special character ( ~!`?@#$%^&*<>,-+=.)", vbCritical + vbOKOnly, "Check MSDOS path"
       txtPath.Text = ""
    End If
End Sub

Private Function CheckMSDOSFolderName(str As String) As Boolean
    Dim specialCharacters As String
    Dim i As Integer
    specialCharacters = " ~!`?@#$%^&*()<>,-+=."
    CheckMSDOSFolderName = True
    
    For i = 1 To Len(specialCharacters) Step 1
        If InStr(1, str, Mid(specialCharacters, i, 1), vbTextCompare) > 0 Then
            CheckMSDOSFolderName = False
            Exit For
        End If
    Next i

End Function

Private Sub Command2_Click() 'Apply
    Call SaveSetting("")
End Sub

Private Sub Command3_Click() 'OK
    Call SaveSetting("")
    Unload Me
End Sub

Private Sub Command4_Click() 'Close
    Unload Me
End Sub

Private Sub Command5_Click() 'Backup Now
    If BackupData Then
        MsgBox "Backup is successful", vbInformation + vbOKOnly, "Backup"
    Else
        MsgBox "Error: System can not backup your data, please Contact the developer", vbCritical + vbOKOnly, "Error"
        Exit Sub
    End If
    lblLastUpdate.Caption = MonthName(Month(Date)) & ", " & Day(Date) & " " & Year(Date)
    Call SaveSetting("")
End Sub

Private Sub Form_Load()
    Me.Top = Screen.Height / 2 - (Me.Height / 1.5)
    Me.Left = Screen.Width / 2 - (Me.Width / 2)
    If getSettingValue("enabledbackup") = "1" Then
        chkEnabledBackup.Value = 1
    Else
        chkEnabledBackup = 0
    End If
    lblLastUpdate = getSettingValue("lastbackup")
    txtDay = getSettingValue("backupeveryday")
    If IsNumeric(getSettingValue("backupeveryday")) Then
        UpDown1.Value = getSettingValue("backupeveryday")
    Else
        UpDown1.Value = 1
    End If
    txtPath.Text = getSettingValue("backupto")
    If getSettingValue("Autobackup") = "1" Then
        optAuto.Value = True
    Else
        optManual.Value = True
    End If
End Sub

Private Sub UpDown1_Change()
    If UpDown1.Value > 1 Then
        txtDay.Text = UpDown1.Value
    Else
        txtDay.Text = 1
    End If
End Sub

Private Function SaveSetting(str As String) As Boolean
    Dim strOfficeStore As String
    strOfficeStore = getOffice
    Open App.Path & "\setting.ini" For Output As #1
    
    Print #1, "OFFICE=" & strOfficeStore
    Print #1, "enabledbackup=" & chkEnabledBackup.Value
    Print #1, "lastbackup=" & lblLastUpdate.Caption
    Print #1, "backupeveryday=" & txtDay.Text
    Print #1, "backupto=" & txtPath.Text
    
    If optAuto.Value = True Then
        Print #1, "Autobackup=1"
    Else
        Print #1, "Autobackup=0"
    End If
    
    Close #1
        
End Function



 

 
